home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / rotate.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  4KB  |  92 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. /*************************************************************************
  17.  *                                                                       *
  18.  *     Copyright (c) 1989                  Hiram Clawson                 *
  19.  *                                                                       *
  20.  *  All rights reserved. No part of this program or publication may be   *
  21.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  22.  *  or translated into any language or computer language, in any form or *
  23.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  24.  *  biological, or otherwise, without the prior written permission of:   *
  25.  *                                                                       *
  26.  *              Hiram Clawson                        (408) 429-5647      *
  27.  *              P. O. Box 3178, Santa Cruz, California 95063-3178 USA    *
  28.  *                                                                       *
  29.  *************************************************************************/
  30. /*************************************************************************
  31.  *        rotate.c: Rotate a 3D point about an arbitrary axis defined    *
  32.  *                by a vector                                            *
  33.  *                                                                       *
  34.  *                Written by Hiram Clawson.                              *
  35.  *                Ported to X11 by Ronald Joe Record.                    *
  36.  *************************************************************************/
  37. #include <math.h>
  38. #include "defines.h"
  39.  
  40. void rotate (old_point, new_point, lambda, rotcos, rotsin, const1 )
  41. triple *old_point;
  42. triple *new_point;
  43. triple *lambda;
  44. double *rotcos;
  45. double *rotsin;
  46. double *const1;
  47. {
  48.     register double f3;
  49. /*
  50.  *
  51.  *    Rotate the point (oldx, oldy, oldz) about the axis defined by
  52.  *    the unit vector, lambda = (lambx, lamby, lambz)
  53.  *    by the angle whose cosine is rotcos and sine is rotsin,
  54.  *    with the extra constant const1, which is 1-rotcos.
  55.  *
  56.  *    The rotation point is the origin: (0, 0, 0).
  57.  *    It is assumed that the point to rotate has been translated to
  58.  *    the origin.  The reason I don't have an argument that would
  59.  *    be the point to rotate about is because I may want to do
  60.  *    several rotations on a translated point, before translating
  61.  *    it back to where it belongs.
  62.  *
  63.  *    You can't have new_point be the same as old_point.
  64.  *    It will not work.
  65.  *
  66.  *    The following three sets of calculations are essentially a
  67.  *    matrix multiply of the oldx,y,z by the rotation cosines giving
  68.  *    the *newx,y,z
  69.  *    f3 is a common factor to each calculation.
  70.  */
  71.     f3 = (*const1) * (    old_point->x * lambda->x 
  72.                 + old_point->y * lambda->y
  73.                 + old_point->z * lambda->z );
  74.  
  75.     new_point->x = ( old_point->x * (*rotcos) )
  76.         - (( (old_point->y * lambda->z )
  77.             - ( old_point->z * lambda->y ) ) * (*rotsin) )
  78.         + ( f3 * lambda->x );
  79.  
  80.     new_point->y = ( old_point->y * (*rotcos) )
  81.         - (( (old_point->z * lambda->x )
  82.             - ( old_point->x * lambda->z ) ) * (*rotsin) )
  83.         + ( f3 * lambda->y );
  84.  
  85.     new_point->z = ( old_point->z * (*rotcos) )
  86.         - (( (old_point->x * lambda->y )
  87.             - ( old_point->y * lambda->x ) ) * (*rotsin) )
  88.         + ( f3 * lambda->z );
  89.  
  90.     return;
  91. }    /* end of rotate */
  92.